﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Castle.ActiveRecord;
using System.Web;
using System.IO;

namespace Windvoice.Albums
{
    public partial class Photo : ActiveRecordBase<Photo>
    {
        public void SetFacePhoto()
        {
            var album = Album.Find(this.AlbumID);
            album.FacePhoto = this.ID;
            album.Save();
        }

        public override void Delete()
        {
            try 
            {
                FileInfo OriginPhotoFile = new FileInfo( HttpContext.Current.Server.MapPath(this.Path));
                OriginPhotoFile.Delete();
                File.Delete(HttpContext.Current.Server.MapPath(this.SmallPath));

                if (OriginPhotoFile.Directory.GetFiles().Count() > 0)
                    OriginPhotoFile.Directory.Delete();
            }
            catch 
            {
            }

            base.Delete();
        }
    }
}
